﻿using MaBlaApp.Data;
using Microsoft.Extensions.Logging;

namespace MaBlaApp;

public static class MauiProgram
{
	public static MauiApp CreateMauiApp()
	{
		var builder = MauiApp.CreateBuilder();
		builder
			.UseMauiApp<App>()
			.ConfigureFonts(fonts =>
			{
				fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
			});

		builder.Services.AddMauiBlazorWebView();

#if DEBUG
		builder.Services.AddBlazorWebViewDeveloperTools();
		builder.Logging.AddDebug();
#endif

		builder.Services.AddSingleton<WeatherForecastService>();
		builder.Services.AddSingleton<TodoService>();
#if ANDROID
		builder.Services.AddSingleton<BleTester>();
#endif

        builder.Services.AddSingleton<LoginUserManager>();

        //NuGet安装Microsoft.Extensions.Http
        //访问Identity Server 4服务器的HttpClient
        builder.Services.AddHttpClient<Ids4Client>()
			.ConfigureHttpClient(c => c.BaseAddress = new Uri("http://localhost:5000"));
		//Windows调试
		//.ConfigureHttpClient(c => c.BaseAddress = new Uri("http://10.0.2.2:5000"));//安卓模拟器，AndroidManifest.xml要添加android:usesCleartextTraffic="true"支持访问http网站

        //设置软件语言
        LangHelper.SetCurrentLang(LangHelper.CurrentLang);

        return builder.Build();
	}
}
